package com.veer.shop.config;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.method.support.HandlerMethodArgumentResolver;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import com.veer.shop.interceptor.ApiLogInterceptor;
import com.veer.shop.interceptor.AuthInterceptor;

/**
 * web相关配置类
 * 
 * @author WangBin
 * 2020年8月12日-上午9:49:47
 */
@Configuration
public class WebConfiguration implements WebMvcConfigurer {
	
	@Bean
	public HandlerInterceptor AuthInterceptor(){
		return new AuthInterceptor();
	}
	
	@Bean
	public HandlerInterceptor ApiLogInterceptor() {
		return new ApiLogInterceptor();
	}
	
	@Autowired
    private UserArgumentResolver userArgumentResolver;
	
	// 重写添加拦截器方法并添加配置拦截器
	@Override
	public void addInterceptors(InterceptorRegistry registry) {
		
		// 接口日志拦截器
		// registry.addInterceptor(ApiLogInterceptor()).addPathPatterns("/**").order(1);
		
		// 接口授权拦截器
		registry.addInterceptor(AuthInterceptor()).addPathPatterns("/**").order(2);
	}
	
	@Override
	public void addArgumentResolvers(List<HandlerMethodArgumentResolver> resolvers) {
		resolvers.add(userArgumentResolver);
	}
}